package com.hc.acoustics.ui.activity

import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.hc.acoustics.R
import com.hc.acoustics.base.BaseActivity
import com.hc.acoustics.bean.contact.MainType
import com.hc.acoustics.bean.domain.ReferenceBean
import com.yc.yclibrary.base.YcAppCompatActivity
import com.yc.yclibx.adapter.YcAdapterHelper
import com.yc.yclibx.adapter.YcRecyclerViewAdapter
import kotlinx.android.synthetic.main.type_formula_activity.*

/**
 *  参考
 */
class ReferenceTypeActivity : BaseActivity() {
    private lateinit var mAdapter: YcRecyclerViewAdapter<ReferenceBean>
    @MainType.State
    private var mMainType: Int = MainType.State.Main_1

    companion object {
        private const val KEY_MAIN_TYPE = "KEY_MAIN_TYPE"
        @JvmStatic
        fun newInstance(activity: YcAppCompatActivity, @MainType.State mainType: Int) {
            val intent = Intent(activity, ReferenceTypeActivity::class.java)
            intent.putExtra(KEY_MAIN_TYPE, mainType)
            activity.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.type_formula_activity
    }

    override fun initView(savedInstanceState: Bundle?) {
        mMainType = intent.getIntExtra(KEY_MAIN_TYPE, MainType.State.Main_1)
        setActionBar(MainType.getTitleName(mMainType))
        mAdapter = object : YcRecyclerViewAdapter<ReferenceBean>(this, R.layout.type_formula_item) {
            override fun onUpdate(helper: YcAdapterHelper, item: ReferenceBean, position: Int) {
                helper.setText(R.id.typeFormulaItemTv, item.title)
            }
        }
        mAdapter.setItemClickListener { viewHolder, view, position ->
            val item = mAdapter.getItem(position)
            if (item.imgResId.size == 1) {
                ShowImageActivity.newInstance(
                    activity,
                    item.title,
                    item.imgResId[0],
                    item.imgIsScroll[0],
                    item.imgBgIsWhite[0]
                )
            } else {
                Reference2TypeActivity.newInstance(activity, item)
            }
        }
        val referenceData: List<ReferenceBean> = arrayListOf(
            ReferenceBean(
                "测量设备连接",
                arrayListOf(
                    R.drawable.reference_1_1,
                    R.drawable.reference_1_2,
                    R.drawable.reference_1_3,
                    R.drawable.reference_1_4,
                    R.drawable.reference_1_5
                ),
                arrayListOf("带有回路档", "含返回线", "Y线测量连线", "家用、汽车音响", "带有信号发生器"),
                arrayListOf(0, 0, 0, 0, 0),
                arrayListOf(true, true, true, true, true)
            ),
            ReferenceBean(
                "话筒的指向性",
                arrayListOf(
                    R.drawable.reference_2_1,
                    R.drawable.reference_2_2,
                    R.drawable.reference_2_3,
                    R.drawable.reference_2_4,
                    R.drawable.reference_2_5
                ),
                arrayListOf("指向性简图", "全指向", "心形", "超心型", "8字型"),
                arrayListOf(0, 0, 0, 0, 0),
                arrayListOf(true, true, true, true, true)
            ),
            ReferenceBean(
                "鼓组传统部件与基础拾音",
                arrayListOf(
                    R.drawable.reference_3_1,
                    R.drawable.reference_3_2,
                    R.drawable.reference_3_3,
                    R.drawable.reference_3_4,
                    R.drawable.reference_3_5,
                    R.drawable.reference_3_6,
                    R.drawable.reference_3_7,
                    R.drawable.reference_3_8
                ),
                arrayListOf(
                    "kick in 底鼓内腔",
                    "kick out 底鼓外鼓皮",
                    "over head、ride 吊镲、叮叮镲",
                    "tom 通鼓",
                    "hi hat 踩镲",
                    "snare bottom 军鼓下皮、响弦",
                    "snare top 军鼓上皮",
                    "floor tom 地通鼓"
                ),
                arrayListOf(0, 0, 0, 0, 0, 0, 0, 0),
                arrayListOf(false, false, false, false, false, false, false, false)
            ),
            ReferenceBean(
                "各类音频线连接方法",
                arrayListOf(R.drawable.reference_4),
                arrayListOf(""),
                arrayListOf(1),
                arrayListOf(true)
            ),
            ReferenceBean(
                "小系统测量",
                arrayListOf(R.drawable.reference_5),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            ),
            ReferenceBean(
                "卡拉OK",
                arrayListOf(R.drawable.reference_6),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            ),
            ReferenceBean(
                "各类乐器频率范围",
                arrayListOf(R.drawable.reference_7),
                arrayListOf(""),
                arrayListOf(1),
                arrayListOf(true)
            ),
            ReferenceBean(
                "相位曲线怎么看",
                arrayListOf(R.drawable.reference_8),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            ),
            ReferenceBean(
                "相位曲线怎么调",
                arrayListOf(R.drawable.reference_9),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            ),
            ReferenceBean(
                "线阵列音箱指向性",
                arrayListOf(R.drawable.reference_10),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            ),
            ReferenceBean(
                "线阵列组合指向性",
                arrayListOf(R.drawable.reference_11),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            ),
            ReferenceBean(
                "百灵达声卡测量说明书",
                arrayListOf(R.drawable.reference_12),
                arrayListOf(""),
                arrayListOf(2),
                arrayListOf(true)
            ),
            ReferenceBean(
                "话筒曲线",
                arrayListOf(R.drawable.reference_13),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            )
            ,
            ReferenceBean(
                "哈斯效应",
                arrayListOf(R.drawable.reference_14),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            )
            ,
            ReferenceBean(
                "等响曲线",
                arrayListOf(R.drawable.reference_15),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            )
            ,
            ReferenceBean(
                "吸音、反射、扩散",
                arrayListOf(R.drawable.reference_16),
                arrayListOf(""),
                arrayListOf(0),
                arrayListOf(true)
            )
        )
        mAdapter.addAll(referenceData)
        typeFormulaRv.adapter = mAdapter
        typeFormulaRv.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
    }
}
